MATLAB Example 6.2
Steps to obtain SETAR parameter estimates with some basic model checking.

1) Run function AICmin.m with p_{max} = m (e.g. m = 8) and 1<= d<= max(1,m) 
   using AIC and input time series y = data.
   
   OUTPUT: 
     A = (m+1)^3 * 11 matrix with elements
         [(p1,p2,p3), (r1,r2), d, RSS, (sigma1,sigma2,sigma3), AIC].
      
   Select p = [p1 p2 p3], d, and (r1,r2) for which AIC is minimal.
   
2) Given the results in part 1), run the function diagnostic.m:
   [beta,RSS,sigma,AIC,res] = diagnostics(y,p,d,r,R)
   with the thresholds r = r1, and R = r2.
   
   OUTPUT: 
   beta = (p1+p2+p3)+3 * 1 vector with parameter estimates
   res  = vector with standardized residuals 
          (Example 6.2: resUSUNEMP.dat)
   
3) Set path to the Econometrics toolbox and compute the 
   diagnostic test statistics:
   [BH, BP, BQstat, BCV] = lbqtest(res, (1:1:24)', 0.05);     % Ljung-Box 
   [LH, LP, LQstat, LCV] = lbqtest(res.^2, (1:1:24)', 0.05);  % McLeod-Li

4) For bootstrapped CIs use the R-code: Bootstrap-limiting-distr.r
